<template>
	<view>
		<uni-section title="搜索" type="line">
			<uni-search-bar @confirm="search" v-model="params.num" @cancel="cancel" @clear="cancel">
			</uni-search-bar>
			<view class="uni-padding-wrap uni-common-mt">
				<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" />
			</view>
		</uni-section>
		<uni-section title="资产列表" type="line">
			<uni-list>
				<uni-list-item v-for="(item, i) in list" :key="i" clickable
					:title="item.num" :note="item.cateName" show-arrow @click="showDetail(item)"
					:rightText="(item.orgName ?item.orgName :'')  + ' ' + (item.modelName ?item.modelName :'')">			
				</uni-list-item>
			</uni-list>
		</uni-section>
		<uni-load-more :status="moreStatus" @clickLoadMore="getList"/>
	</view>
</template>

<script>
	import {selectInfo} from '@/api/asset.js'
	import { dictMixin } from '@/plugins/dict.js';
	export default {
		mixins: [dictMixin],
		data() {
			return {
				list:[],
				items: ['全部'],
				current: 0,
				moreStatus:'noMore',
				params:{
					num:null,
					status:null,
					pageSize: 10,
					pageNum: 1,
					orderByColumn: 't.id',
					isAsc: 'DESC'
				}
			}
		},
		onLoad() {
			this.getList();
			
			this.useDict(['asset_status'], ()=>{
				for(let i=0;i<this.dictOptions['asset_status'].length;i++){
					this.items.push(this.dictOptions['asset_status'][i].dictLabel);
				}
			});	
		},
		methods: {			
			onClickItem(e) {
				this.params.status = null;
				if(e.currentIndex == 0){
					this.params.status = null;
				}else{
					this.params.status = this.dictOptions['asset_status'][e.currentIndex-1].dictValue;
				}
				this.params.pageNum = 1;
				this.list = [];
				this.getList();
			},
			
			getList() {
				this.moreStatus = 'loading';
				selectInfo(this.params).then(response=>{					
					if(response.data == null || response.data.length == 0){
						this.moreStatus = 'noMore';
					}
					
					if(this.params.pageNum == 1){
						this.list = response.data;
					}else{
						this.list = this.list.concat(response.data);
					}
					
					if(response.data.length < this.params.pageSize){
						this.moreStatus = 'noMore';
					}else{						
						this.moreStatus = 'more';
						this.params.pageNum += 1;
					}
				})
			},
			search(res) {
				this.params.pageNum = 1;
				this.list = [];
				this.getList();
			},
			cancel(res) {
				this.params.num = null;
				this.list = [];
				this.search();
			},
			showDetail(item) {				
				this.$tab.navigateTo('/pages/asset/detail?id='+item.id);
			}
		}
	}
</script>

<style>
	.uni-common-mt {
		margin-top: 10px;
	}

	.uni-padding-wrap {
		// width: 750rpx;
		padding: 0px 10px;
	}
</style>